package com.tzy.collection.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tzy.collection.mapper.MyCollectionMapper;
import com.tzy.common.entity.MyCollection;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 我的收藏表 服务实现类
 * </p>
 *
 * @author 姣姣同学
 * @since 2022-03-01
 */
@Service
public class MyCollectionService extends ServiceImpl<MyCollectionMapper,MyCollection> implements IMyCollectionService {
    @Resource
    private MyCollectionMapper myCollectionMapper;

//    @Cacheable(cacheNames = "list")
    public List<Map<String,Object>> getList(){
        return myCollectionMapper.findList();
    }


//    @Cacheable(cacheNames = "list")
    public List<Map<String,Object>> getListByUserId(int userId){
        return myCollectionMapper.findListById(userId);

    }
    /**
     * 添加收藏
     * @param entity
     */
    @Override
    @Transactional(rollbackFor = Exception.class)//表示遇到异常就回滚
    public boolean save(MyCollection entity) {
        return super.save(entity);
    }
    /**
     *
     * @param entity
     * @return
     */
    @Override
    @Transactional
    @CacheEvict(value = {"list"},allEntries = true)//allEntries = true清除所有缓存
    public boolean updateById(MyCollection entity) {
        return super.updateById(entity);
    }


/**
     *根据收藏id删除
     * @param id
     * @return 收藏id
     */
    //调用父类的删除方法
    @Override
    @Transactional
    public boolean removeById(Serializable id) {
        return super.removeById(id);
    }


}
